<!--老师查看学生毕设资料完成情况-->
<style>
	.yanse {
		width: 20px;
		height: 20px;
		display: inline-block;
		line-height: 20px;
	}
	
	.input-group {
		margin-bottom: 40px;
	}
	
	.xiaofangkuai {
		display: inline-block;
	}
	
	.turn {
		word-break: break-all;
	}
	
	.table td {
		width: 100%;
		word-break: break-all;
		white-space: normal;
	}
</style>

<table class="table table-striped table-bordered table-hover turn" id="tr_look">
	<thead>
		<tr>
			<th col style="width: 12%">毕设阶段</th>
			<th col style="width: 40%">已完成</th>
			<th col style="width: 35%">未完成</th>
			<th col style="width: 15%">导出学生毕设资料</th>
		</tr>
	</thead>
</table>
<script>
	var reports = [0, 1, 2, 3];
	var myajax;

	jieduan(0, reports);

	//利用递归实现ajax顺序执行
	function jieduan(index, reports) {

		var type = reports[index];

		myajax = $.ajax({ //查看开题报告
			xhrFields: {
				withCredentials: true
			},
			type: 'get',
			url: getFullURL('teacher/check-progress'),
			data: {
				type: type //0开题报告,1任务书,2终稿,3定稿
			},
			dataType: 'json',
			success: function(data) {
				console.log(data)
				if(data.status == 0) {

					var path = 'teacher/down-bishefile?type=' + type;

					var yiwancheng = '';
					var weiwancheng = '';
					var jieduan = '';

					if(type == 0) {
						jieduan = "开题报告阶段"
					} else if(type == 1) {
						jieduan = "任务书阶段"
					} else if(type == 2) {
						jieduan = "毕设终稿阶段"
					} else if(type == 3) {
						jieduan = "毕设定稿阶段"
					}

					$.each(data.stuFileList, function(i, n) {
						yiwancheng = yiwancheng + " " + n.name
					})

					$.each(data.stuNoFileList, function(i, n) {
						weiwancheng = weiwancheng + " " + n.name
					})

					var table_content = `<tr>
	        			<td>` + jieduan + `</td>
					    <td>` + yiwancheng + `</td>
					    <td>` + weiwancheng + `</td>
					    <td><button id="xiazai_` + type + `" type="button" class="btn btn-default">一键下载</button></td>
					    </tr>`;

					$('#tr_look').append(table_content);

					var xiazai = "#xiazai_" + type;
					$(xiazai).click(function() {
						if(data.stuFileList.length != 0) {
							window.open(getFullURL(path));
						} else {
							alert("还未有学生上传资料");
						}
					})
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})

		$.when(myajax).done(function() {
			index++;
			if(index < reports.length) {
				jieduan(index, reports);
			}
		});
	}
</script>